<template>
	<view class="page">
    <u-subsection :list="list" :current="curNow" @change="sectionChange"></u-subsection>
    <view style="height: 200px;" v-for="(item,index) in orderList"  :key="index" >
      <view carBox-item style="height: 200px;border: 1px solid #4d4640;border-radius: 20px;margin: 20px 10px;" >
              <img @click="goDetail(item)" style="width: 100px;height:200px;float: left;border-radius: 20px;" :src="item.img"  alt="" />
						  <view>
                <view @click="goDetail(item)" style="margin-top: 3px;" >{{item.name}}</view>
							  <view style="margin-top: 3px;">单价：{{ item.price }}积分  </view>
                <view style="margin-top: 3px;">购买数量:{{ item.count }} </view>
                <view style="margin-top: 3px;">总金额:{{ item.price*item.count }}积分 </view>
                <button v-if="curNow ==0" style="width: 100px;border-radius: 20px;margin-top: 10px;" @click="goOff(item)">取消订单</button>
                <!-- <button v-if="curNow ==0" style="width: 100px;border-radius: 20px;margin-top: 20px;" @click="goSure(item)">确认发货</button> -->
                <button v-if="curNow ==1" style="width: 100px;border-radius: 20px;margin-top: 10px;" @click="goSure(item)">确认收货</button>
                <!-- <button v-if="curNow ==2" style="width: 100px;border-radius: 20px;margin-top: 10px;" @click="goAfter()">常见问题</button> -->
						  </view>
        </view>
    </view>
	</view>
</template>

<script>
import {baseUrl} from '@/config'
export default {

	data() {
		return {
      userId:'',
      orderList:[],
      list: ['待发货', '待收货', '已完成'],
      curNow: 0,
      status:0
		};
	},
	onShow() {
    this.userId=uni.getStorageSync('user').data[0].userId
	  this.getorderList()
	},
	methods: {
    goDetail(item){
      var sid = item.sid
      uni.navigateTo({
                  url:`/pages/shop-order-detail/index?sid=${sid}`
              })

    },
    goAfter(){
      uni.navigateTo({
        url:'/pages/after/index'
      })
    },
    goSure(item){
      uni.request({
        method: 'POST',
              header: {
                'Content-Type': 'application/x-www-form-urlencoded'
              },
              url: baseUrl+'/v1/order/shopOrderStatusUpdate',
              data:{
                sid : item.sid,
                status : parseInt(item.status)+1
              },
              success: () => {
                this.getorderList()
                }
          });
          
    },
    goOff(item){
      // console.log(item);
      uni.request({
              url: baseUrl+'/v1/order/shopOrderDelete',
              data:{
                sid:item.sid
              },
              success: () => {
                this.getorderList()
                }
          });
    },
    sectionChange(index) {
				this.curNow = index;
        this.status = this.curNow
        this.getorderList()
			},
    getorderList(){
        uni.request({
              url: baseUrl+'/v1/order/shopOrderStatusSearch',
              data:{
                userId:this.userId,
                status:this.status
              },
              success: (res) => {
                console.log(res.data.code);
                if(res.data.code == 200){
                  this.orderList = res.data.data
                }else{
                  this.orderList = []
                }
                
                }
          });
    }

	}
};
</script>

<style lang="scss" scoped>

</style>
